"use strict";

import { Tree } from 'antd';
import Immutable from 'immutable';
import {msg} from 'iflux';
const TreeNode = Tree.TreeNode;

export default class ImgCateTree extends React.Component{
    static defaultProps = {
        cateTreeData:Immutable.fromJS([]),
        selectNodeId:'0',
        expandedKeys:Immutable.fromJS([])
    };
    render() {
        const loop = data => data.map((item) => {
            if (item.children && item.children.length) {
                return (
                    <TreeNode title={item.name}  pid={item.pid} id={item.id} key={item.id} info={JSON.stringify(item)}>
                        {loop(item.children)}
                    </TreeNode>
                );
            }
            return <TreeNode title={item.name}  pid={item.pid} id={item.id} key={item.id} info={JSON.stringify(item)} disabled={item.key === '0'} isLeaf={item.isLeaf}/>;
        });
        return (
            <Tree expandedKeys={this.props.expandedKeys.toJS()} onSelect={(keys,e)=>{msg.emit('get::cateTree::and::img::by::pid',keys[0])}} selectedKeys={[this.props.selectNodeId]}>
                {loop(this.props.cateTreeData.toJS())}
            </Tree>
        );
    }
}